package cn.tedu.shoppingmall.mapper;

import cn.tedu.shoppingmall.vo.Commodity;
import cn.tedu.shoppingmall.vo.Shopcar;
import org.apache.ibatis.annotations.*;

import java.util.List;
//购物车数据库增删改查操作
@Mapper
public interface ShopMapper {
    //把商品信息增加到购物车表中
    @Insert("insert into shopcar values(null,#{name},#{intro},1,#{userid}" +
            ",#{comid},#{price},#{salesnum},#{created},#{classId},#{url})")
    void insertToShopcar(Shopcar s);

    //将购物车中的单个商品删除
    @Delete("delete from shopcar where id=#{id}")
    void deleteShopcarOne(int id);

    //将购物车表中单个商品存在数量+1
    @Update("update shopcar set sum=sum-1 where id=#{id}")
    int delToShopcarSum(int id);
    //将购物车表中单个商品存在数量-1
    @Update("update shopcar set sum=sum+1 where id=#{id}")
    int addToShopcarSum(int id);
    //首页加入购物车时单个商品存在数量+1
    @Update("update shopcar set sum=sum+1 where userid=#{uid} and comid=#{comid} ")
    void insertToShopcarOne(int comid, Integer uid);

    //根据用户id查询购物车表里的数据 --->购物车页显示数据
    @Select("select * from shopcar where userid=#{id}")
    List<Shopcar> getshopcar(int id);
    //根据用户id和商品id查询购物车表里的单个信息数据
    @Select("select * from shopcar where userid=#{uid} and comid=#{comid}")
    Shopcar selectByUserid(int comid, Integer uid);
    ///根据商品id查询购物车表里的单个信息数据
    @Select("select * from shopcar where id=#{id}")
    Shopcar SelectShopcarById(int id);

}
